package com.chengliang.zuoye.controller;

import com.chengliang.zuoye.bean.User;
import com.chengliang.zuoye.service.MenuService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 首页
 * @author jerry
 */
@Controller
public class IndexController {

    private final MenuService menuService;

    public IndexController(MenuService menuService) {
        this.menuService = menuService;
    }

    /**
     * 首页
     */
    @RequestMapping("/")
    public String index(Model model){
        model.addAttribute("menuList",menuService.oneMenuList());
        User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        model.addAttribute("oneMenuIdList",menuService.getOneMenuListByRoleId(principal.getRoleId()));
        model.addAttribute("twoMenuIdList",menuService.getTwoMenuListByRoleId(principal.getRoleId()));
        return "index";
    }
}
